<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>柱形图示例</title>
<style>
  .bar-container {
    display: flex;
    align-items: flex-end;
    justify-content: space-around;
    margin-bottom: 20px;
  }
  .bar {
    width: 50px;
    margin-right: 10px;
    background-color: #3498db;
    text-align: center;
    color: white;
    padding: 5px;
  }
  .label {
    margin-left: 10px;
  }
</style>
</head>
<body>

<div id="chart"></div>

<script>
  // 获取图表容器
  let chartContainer = document.getElementById('chart');

  // 用于存储季度数据的数组
  let quartersData = new Array(4);

  // 循环四次，获取四个季度的数据
  for (let i = 0; i < 4; i++) {
    quartersData[i] = Number(prompt("请输入第" + (i + 1) + "季度的数据："));
  }

  // 遍历数组，生成柱形图
  for (let i = 0; i < quartersData.length; i++) {
    let barContainer = document.createElement("div");
    barContainer.className = "bar-container";

    let bar = document.createElement("div");
    bar.style.height = quartersData[i] * 2 + "px"; // 假设数据乘以2作为高度
    bar.className = "bar";

    let label = document.createElement("div");
    label.className = "label";
    label.innerHTML = "第" + (i + 1) + "季度: " + quartersData[i];

    bar.appendChild(label);
    barContainer.appendChild(bar);
    chartContainer.appendChild(barContainer);
  }
</script>

</body>
</html>